home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / plotting / imagetoo / imagetl1.lha / Imagetool / src+obj / stack.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-11  |  23.9 KB  |  859 lines

  1. /* cat > headers/stack.h << "EOF" */
  2. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  3. /* stack.h: header for stack.c file            */
  4. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  5. /* SCCS information: %W%    %G% - NCSA */
  6.  
  7. #define    stack_h        1
  8.  
  9. #include "all.h"
  10. #include "newext.h"
  11.  
  12. /* EOF */
  13. /* cat > src+obj/stack/create_entrysw.c << "EOF" */
  14. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  15. /* create_entrysw: create stack entry frame        */
  16. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  17. /* SCCS information: %W%    %G% - NCSA */
  18.  
  19. /* #include "option.h" */
  20.  
  21. int
  22. create_entrysw ()
  23. {
  24.     int             x_origin, y_origin;
  25.     int             x_offset, y_offset;
  26.  
  27.     if (window_corner (canvas, LEFT, TOP, &x_origin, &y_origin))
  28.     {
  29.         printf ("Internal error: (create_entrysw) Can't get dimensions of canvas frame - ImageTool terminated!");
  30.         exit (-1);
  31.     }
  32.  
  33.     x_offset = 150;
  34.     y_offset = 75;
  35.  
  36.     entry_frame = window_create (base, FRAME,
  37.                      FRAME_SHOW_LABEL, TRUE,
  38.                      WIN_SHOW, FALSE,
  39.                      WIN_X, x_origin + x_offset,
  40.                      WIN_Y, y_origin + y_offset,
  41.                      WIN_COLUMNS, 80,
  42.                      0);
  43.         /* panel with entry data */
  44.     entry_panel1 = window_create (entry_frame, PANEL,
  45.                       PANEL_FONT, font_panel,
  46.                       PANEL_LABEL_BOLD, TRUE,
  47.                       WIN_ROWS, 10,
  48.                       0);
  49.     entry_item1 = panel_create_item (entry_panel1, PANEL_TEXT,
  50.                      PANEL_VALUE_DISPLAY_LENGTH, 64,
  51.                      PANEL_VALUE_STORED_LENGTH, MAXNAMELEN - 1,
  52.                      PANEL_LABEL_STRING, "image file name:",
  53.                      0);
  54.     entry_item2 = panel_create_item (entry_panel1, PANEL_TEXT,
  55.                      PANEL_VALUE_DISPLAY_LENGTH, 64,
  56.                      PANEL_VALUE_STORED_LENGTH, MAXNAMELEN - 1,
  57.                      PANEL_LABEL_STRING, "palette file name:",
  58.                      0);
  59.     window_fit_height (entry_panel1);
  60.  
  61.         /* panel with buttons */
  62.     entry_panel2 = window_create (entry_frame, PANEL,
  63.                       PANEL_FONT, font_panel,
  64.                       PANEL_LABEL_BOLD, TRUE,
  65.                       WIN_BELOW, entry_panel1,
  66.                       WIN_ROWS, 3,
  67.                       0);
  68.     panel_create_item (entry_panel2, PANEL_BUTTON,
  69.                PANEL_LABEL_IMAGE, panel_button_image (entry_panel2, "+", 3, font_panel_button),
  70.                PANEL_CLIENT_DATA, 1,
  71.                PANEL_NOTIFY_PROC, entry_proc,
  72.                0);
  73.     panel_create_item (entry_panel2, PANEL_BUTTON,
  74.                PANEL_LABEL_IMAGE, panel_button_image (entry_panel2, "-", 3, font_panel_button),
  75.                PANEL_CLIENT_DATA, 2,
  76.                PANEL_NOTIFY_PROC, entry_proc,
  77.                0);
  78.     panel_create_item (entry_panel2, PANEL_BUTTON,
  79.                PANEL_LABEL_IMAGE, panel_button_image (entry_panel2, "Show", 6, font_panel_button),
  80.                PANEL_CLIENT_DATA, 3,
  81.                PANEL_NOTIFY_PROC, entry_proc,
  82.                0);
  83.     panel_create_item (entry_panel2, PANEL_BUTTON,
  84.                PANEL_LABEL_IMAGE, panel_button_image (entry_panel2, "Delete", 6, font_panel_button),
  85.                PANEL_CLIENT_DATA, 4,
  86.                PANEL_NOTIFY_PROC, entry_proc,
  87.                0);
  88.     panel_create_item (entry_panel2, PANEL_BUTTON,
  89.                PANEL_LABEL_IMAGE, panel_button_image (entry_panel2, "Cancel", 6, font_panel_button),
  90.                PANEL_CLIENT_DATA, 5,
  91.                PANEL_NOTIFY_PROC, entry_proc,
  92.                0);
  93.     window_fit_height (entry_panel2);
  94.     window_fit_height (entry_frame);
  95.  
  96.         /* set color map same with ImageTool */
  97.     (void) color_entry_win ();
  98. }
  99. /* EOF */
  100. /* cat > src+obj/stack/create_stack_panel.c << "EOF" */
  101. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  102. /* create_stack_panel: create panel and menu objects     */
  103. /*               for stacking            */
  104. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  105. /* SCCS information: %W%    %G% - NCSA */
  106.  
  107. /* #include "stack.h" */
  108.  
  109. create_stack_panel ()
  110. {
  111.     int             x, y, ix, iy;
  112.  
  113.     x = 50;
  114.     ix = 75;
  115.     y = 50;
  116.  
  117.         /* panel and menu objects for stacking */
  118.     stack_menu = menu_create (MENU_STRINGS,
  119.                   "1",
  120.                   "2",
  121.                   "3",
  122.                   "4",
  123.                   "5",
  124.                   "6",
  125.                   "7",
  126.                   "8",
  127.                   "9",
  128.                   "10",
  129.                   0,
  130.                   MENU_FONT, font_menu,
  131.                   MENU_GEN_PROC, stack_mark_menu,
  132.                   MENU_NOTIFY_PROC, stack_request,
  133.                   0);
  134.     store_but = panel_create_item (panel, PANEL_BUTTON,
  135.                        PANEL_ITEM_X, x,
  136.                        PANEL_ITEM_Y, y,
  137.                        PANEL_LABEL_IMAGE, panel_button_image (panel, "Store", 6, font_panel_button),
  138.                        PANEL_SHOW_ITEM, FALSE,
  139.                        PANEL_CLIENT_DATA, 1,
  140.                        PANEL_EVENT_PROC, stack_event,
  141.                        0);
  142.     store_but_msg = panel_create_item (panel, PANEL_MESSAGE,
  143.                        PANEL_ITEM_X, x + 15,
  144.                        PANEL_ITEM_Y, y + 30,
  145.                        PANEL_LABEL_STRING, "  ",
  146.                        PANEL_SHOW_ITEM, FALSE,
  147.                        0);
  148.     show_menu = menu_create (MENU_ITEM,
  149.                      MENU_STRING, "Image",
  150.                      MENU_FONT, font_menu,
  151.                      MENU_PULLRIGHT, stack_menu,
  152.                      0,
  153.                  MENU_ITEM,
  154.                      MENU_STRING, "Entry data",
  155.                      MENU_FONT, font_menu,
  156.                      MENU_ACTION_PROC, stack_request,
  157.                      0,
  158.                  0);
  159.  
  160.     show_but = panel_create_item (panel, PANEL_BUTTON,
  161.                       PANEL_ITEM_X, x + ix,
  162.                       PANEL_ITEM_Y, y,
  163.                       PANEL_LABEL_IMAGE, panel_button_image (panel, "Show", 6, font_panel_button),
  164.                       PANEL_CLIENT_DATA, 2,
  165.                       PANEL_SHOW_ITEM, FALSE,
  166.                       PANEL_EVENT_PROC, stack_event,
  167.                       0);
  168.     show_but_msg = panel_create_item (panel, PANEL_MESSAGE,
  169.                       PANEL_ITEM_X, x + 15 + ix,
  170.                       PANEL_ITEM_Y, y + 30,
  171.                       PANEL_LABEL_STRING, "  ",
  172.                       PANEL_SHOW_ITEM, FALSE,
  173.                       0);
  174.     delete_but = panel_create_item (panel, PANEL_BUTTON,
  175.                     PANEL_ITEM_X, x + 2 * ix,
  176.                     PANEL_ITEM_Y, y,
  177.                     PANEL_LABEL_IMAGE, panel_button_image (panel, "Delete", 6, font_panel_button),
  178.                     PANEL_CLIENT_DATA, 3,
  179.                     PANEL_SHOW_ITEM, FALSE,
  180.                     PANEL_EVENT_PROC, stack_event,
  181.                     0);
  182.     delete_but_msg = panel_create_item (panel, PANEL_MESSAGE,
  183.                         PANEL_ITEM_X, x + 15 + 2 * ix,
  184.                         PANEL_ITEM_Y, y + 30,
  185.                         PANEL_LABEL_STRING, "  ",
  186.                         PANEL_SHOW_ITEM, FALSE,
  187.                         0);
  188.     flush_but = panel_create_item (panel, PANEL_BUTTON,
  189.                        PANEL_ITEM_X, x + 3 * ix,
  190.                        PANEL_ITEM_Y, y,
  191.                        PANEL_LABEL_IMAGE, panel_button_image (panel, "Flush", 6, font_panel_button),
  192.                        PANEL_MENU_CHOICE_STRINGS, "Flush storage", 0,
  193.                        PANEL_SHOW_MENU, TRUE,
  194.                        PANEL_SHOW_ITEM, FALSE,
  195.                        PANEL_NOTIFY_PROC, flush_table,
  196.                        0);
  197. }
  198. /* EOF */
  199. /* cat > src+obj/stack/delete_entry.c << "EOF" */
  200. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  201. /* delete_entry: delete a table entry            */
  202. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  203. /* SCCS information: %W%    %G% - NCSA */
  204.  
  205. /* #include "stack.h" */
  206.  
  207. delete_entry (index)
  208.     int             index;
  209.                 /* input: index of entry to delete */
  210. {
  211.     pr_close (var_table[index].image);
  212.     free (var_table[index].red);
  213.     free (var_table[index].green);
  214.     free (var_table[index].blue);
  215.     var_table[index].in_use = 0;
  216.     var_table[index].image = NULL;
  217.     sprintf (wkstr, "Note: Entry %d deleted.", index + 1);
  218.     msg_write (wkstr);
  219.  
  220.     sprintf (wkstr, "%2d", index + 1);
  221.     panel_set (delete_but_msg, PANEL_LABEL_STRING, wkstr, 0);
  222.     return;
  223. }
  224. /* EOF */
  225. /* cat > src+obj/stack/display_entrysw.c << "EOF" */
  226. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  227. /* display_entrysw: display stack entry frame        */
  228. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  229. /* SCCS information: %W%    %G% - NCSA */
  230.  
  231. /* #include "stack.h" */
  232.  
  233. int
  234. display_entrysw (index)
  235.     int             index;
  236.                 /* input: index in entry table starting at 0. */
  237. {
  238.     set_entry (index);
  239.  
  240.     window_set (entry_frame, WIN_SHOW, TRUE, 0);
  241. }
  242. /* EOF */
  243. /* cat > src+obj/stack/entry_proc.c << "EOF" */
  244. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  245. /* entry_proc: notify proc for entry frame buttons     */
  246. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  247. /* SCCS information: %W%    %G% - NCSA */
  248.  
  249. /* #include "stack.h" */
  250.  
  251. entry_proc (item, event)
  252.     Panel_item      item;
  253.     Event          *event;
  254. {
  255.     int             which_but, which_entry, i, j;
  256.  
  257.     which_but = (int) panel_get (item, PANEL_CLIENT_DATA);
  258.     which_entry = (int) window_get (entry_frame, WIN_CLIENT_DATA) - 1;
  259.     switch (which_but)
  260.     {
  261.         case 1:        /* display next "higher" table entry data - rap around */
  262.             j = (which_entry == MAXTABLE) ? 0 : which_entry + 1;
  263.             for (i = 0; i < MAXTABLE + 1; i++)
  264.                 if (var_table[j].in_use == 1)
  265.                     break;
  266.                 else
  267.                     j = (j == MAXTABLE) ? 0 : j + 1;
  268.             set_entry (j);
  269.             break;
  270.         case 2:        /* display next lower table entry data */
  271.             j = (which_entry == 0) ? j = MAXTABLE : which_entry - 1;
  272.             for (i = 0; i < MAXTABLE + 1; i++)
  273.                 if (var_table[j].in_use == 1)
  274.                     break;
  275.                 else
  276.                     j = (j == 0) ? j = MAXTABLE : j - 1;
  277.             set_entry (j);
  278.             break;
  279.  
  280.         case 3:        /* show the current table entry image on the canvas - puts away this frame */
  281.             window_set (entry_frame, WIN_SHOW, FALSE, 0);
  282.             show_entryimage (which_entry);
  283.             break;
  284.         case 4:        /* delete the current table entry - go to next higher entry */
  285.             delete_entry (which_entry);
  286.             j = (which_entry == MAXTABLE) ? 0 : which_entry + 1;
  287.             for (i = 0; i < MAXTABLE + 1; i++)
  288.                 if (var_table[j].in_use == 1)
  289.                     break;
  290.                 else
  291.                     j = (j == MAXTABLE) ? 0 : j + 1;
  292.             if (i < MAXTABLE + 1)
  293.                 set_entry (j);
  294.             else
  295.             {
  296.                 window_set (entry_frame, WIN_SHOW, FALSE, 0);
  297.                 msg_write ("Warning: Stack table empty! Nothing shown.");
  298.                 break;
  299.             }
  300.             break;
  301.         case 5:        /* put away this frame */
  302.             window_set (entry_frame, WIN_SHOW, FALSE, 0);
  303.             break;
  304.     }
  305. }
  306. /* EOF */
  307. /* cat > src+obj/stack/flush_call.c << "EOF" */
  308. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  309. /* flush_call: deallocate any memory associated with    */
  310. /*           table                    */
  311. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  312. /* SCCS information: %W%    %G% - NCSA */
  313.  
  314. /* #include "stack.h" */
  315.  
  316. flush_call ()
  317. {
  318.     int             i;
  319.  
  320.     for (i = 0; i <= MAXTABLE; i++)
  321.     {
  322.         if (var_table[i].in_use == 1)
  323.             pr_close (var_table[i].image);
  324.         var_table[i].in_use = 0;
  325.         var_table[i].image = NULL;
  326.         free (var_table[i].red);
  327.         free (var_table[i].green);
  328.         free (var_table[i].blue);
  329.     }
  330.     msg_write ("Note: Image table flushed.");
  331. }
  332. /* EOF */
  333. /* cat > src+obj/stack/flush_table.c << "EOF" */
  334. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  335. /* flush_table: fush the table                */
  336. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  337. /* SCCS information: %W%    %G% - NCSA */
  338.  
  339. /* #include "stack.h" */
  340.  
  341. flush_table (item, event)
  342.     Panel_item      item;
  343.     Event          *event;
  344. {
  345.         /* deallocate table storage */
  346.     flush_call ();
  347.  
  348.     panel_set (store_but_msg, PANEL_LABEL_STRING, "  ", 0);
  349.     panel_set (show_but_msg, PANEL_LABEL_STRING, "  ", 0);
  350.     panel_set (delete_but_msg, PANEL_LABEL_STRING, "  ", 0);
  351.  
  352.     if ((int) window_get (entry_frame, WIN_SHOW))
  353.         window_set (entry_frame, WIN_SHOW, FALSE, 0);
  354.  
  355.     erase_all ();
  356.  
  357.     clear_request = 0;
  358.     first_middle_down = 0;
  359.  
  360.     return;
  361. }
  362. /* EOF */
  363. /* cat > src+obj/stack/invalid_stack.c << "EOF" */
  364. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  365. /* invalid_stack: invalid stack                */
  366. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  367. /* SCCS information: %W%    %G% - NCSA */
  368.  
  369. /* #include "stack.h" */
  370.  
  371. invalid_stack ()
  372. {
  373.     Menu_item       item;
  374.  
  375.     panel_set (store_but, PANEL_SHOW_ITEM, FALSE, 0);
  376.     panel_set (store_but_msg, PANEL_SHOW_ITEM, FALSE, 0);
  377.  
  378.     panel_set (show_but, PANEL_SHOW_ITEM, FALSE, 0);
  379.     panel_set (show_but_msg, PANEL_SHOW_ITEM, FALSE, 0);
  380.  
  381.     panel_set (delete_but, PANEL_SHOW_ITEM, FALSE, 0);
  382.     panel_set (delete_but_msg, PANEL_SHOW_ITEM, FALSE, 0);
  383.  
  384.     panel_set (flush_but, PANEL_SHOW_ITEM, FALSE, 0);
  385.  
  386.     item = menu_get (image_menu, MENU_NTH_ITEM, 3, 0);
  387.     menu_set (item, MENU_INACTIVE, FALSE, 0);
  388. }
  389. /* EOF */
  390. /* cat > src+obj/stack/put_table.c << "EOF" */
  391. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  392. /* put_table: put image in table            */
  393. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  394. /* SCCS information: %W%    %G% - NCSA */
  395.  
  396. /* #include "stack.h" */
  397.  
  398. put_table (i)
  399.     int             i;
  400. {
  401.     int             status;
  402.  
  403.     if ((status = store_in_mem (i)))
  404.     {        /* memory allocation problem */
  405.         sprintf (msgstr, "Error: Not enough memory. Stacking image in entry %d failed.", i + 1);
  406.         msg_write (msgstr);
  407.         return (-1);
  408.     }
  409.  
  410.     strcpy (var_table[i].img_name, curr_image.img_name);
  411.     strcpy (var_table[i].pal_name, curr_pal.fn);
  412.  
  413.     var_table[i].org_xdim = curr_image.org_xdim;
  414.     var_table[i].org_ydim = curr_image.org_ydim;
  415.     var_table[i].xdim = curr_image.xdim;
  416.     var_table[i].ydim = curr_image.ydim;
  417.     var_table[i].expanded = curr_image.expanded;
  418.     var_table[i].zoomx = curr_image.zoomx;
  419.     var_table[i].zoomy = curr_image.zoomy;
  420.  
  421.     var_table[i].itype = curr_image.itype;
  422.     var_table[i].img_num = curr_image.img_num;
  423.     var_table[i].ptype = curr_image.ptype;
  424.     var_table[i].pal_num = curr_image.pal_num;
  425.  
  426.     var_table[i].in_use = 1;
  427.  
  428.     sprintf (msgstr, "Note: Entry %d stored.", i + 1);
  429.     msg_write (msgstr);
  430.  
  431.     sprintf (wkstr, "%2d", i + 1);
  432.     panel_set (store_but_msg, PANEL_LABEL_STRING, wkstr, 0);
  433. }
  434. /* EOF */
  435. /* cat > src+obj/stack/set_entry.c << "EOF" */
  436. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  437. /* set_entry: display stack entry frame            */
  438. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  439. /* SCCS information: %W%    %G% - NCSA */
  440.  
  441. /* #include "stack.h" */
  442.  
  443. int
  444. set_entry (index)
  445.     int             index;
  446.                 /* input: index in entry table starting at 0.
  447.                       It is assumed that the entry is in
  448.                       use. */
  449. {
  450.         /* set values - dummy now */
  451.     panel_set_value (entry_item1, default_cdir);
  452.     panel_set_value (entry_item2, default_pal.fn);
  453.  
  454.     window_set (entry_frame, WIN_CLIENT_DATA, index + 1, 0);
  455.     sprintf (wkstr, "Data: table entry %d", index + 1);
  456.     window_set (entry_frame, FRAME_LABEL, wkstr, 0);
  457. }
  458. /* EOF */
  459. /* cat > src+obj/stack/show_entryimage.c << "EOF" */
  460. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  461. /* show_entryimage: display the entry table image     */
  462. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  463. /* SCCS information: %W%    %G% - NCSA */
  464.  
  465. /* #include "stack.h" */
  466.  
  467. show_entryimage (value)
  468.     int             value;
  469. {
  470.     clear_request = 0;
  471.     square_drawn = 0;
  472.     first_middle_down = 0;
  473.  
  474.     show_on_canvas (value);
  475.  
  476.     sprintf (wkstr, "%2d", value + 1);
  477.     panel_set (show_but_msg, PANEL_LABEL_STRING, wkstr, 0);
  478.  
  479.     return;
  480. }
  481. /* EOF */
  482. /* cat > src+obj/stack/show_on_canvas.c << "EOF" */
  483. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  484. /* show_on_canvas: playback image from memory        */
  485. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  486. /* SCCS information: %W%    %G% - NCSA */
  487.  
  488. /* #include "stack.h" */
  489.  
  490. show_on_canvas (i)
  491.     int             i;
  492. {
  493.     int             xdim, ydim;
  494.     char           *fn, *pn;
  495.     static struct pixrect *pr;
  496.  
  497.     erase_last ();
  498.  
  499.     if (var_table[i].in_use == 0)
  500.     {
  501.         sprintf (msgstr, "Warning: Entry %d is empty.", i + 1);
  502.         msg_write (msgstr);
  503.         return (-1);
  504.     }
  505.  
  506.     fn = var_table[i].img_name;
  507.     pn = var_table[i].pal_name;
  508.     xdim = var_table[i].xdim;
  509.     ydim = var_table[i].ydim;
  510.     pr = var_table[i].image;
  511.  
  512.         /* set palette and load image */
  513.     color_win (var_table[i].red, var_table[i].green, var_table[i].blue);
  514.     pw_write (pw, startx, starty, xdim, ydim, PIX_SRC, pr, 0, 0);
  515.     panel_set_value (image_board, fn);
  516.     panel_set_value (pal_board, pn);
  517.  
  518.     sprintf (msgstr, "Note: Now showing entry %d. Size = (%d, %d)", i + 1, xdim, ydim);
  519.     msg_write (msgstr);
  520.     msg_write ("      Image and palette originally from entries above.");
  521.  
  522.     strcpy (curr_image.img_name, fn);
  523.     strcpy (curr_image.pal_name, pn);
  524.  
  525.     curr_image.itype = var_table[i].itype;
  526.     curr_image.img_num = var_table[i].img_num;
  527.     curr_image.ptype = var_table[i].ptype;
  528.     curr_image.pal_num = var_table[i].pal_num;
  529.  
  530.     curr_image.startx = startx;
  531.     curr_image.starty = starty;
  532.     curr_image.org_xdim = var_table[i].org_xdim;
  533.     curr_image.org_ydim = var_table[i].org_ydim;
  534.     curr_image.xdim = xdim;
  535.     curr_image.ydim = ydim;
  536.     curr_image.image = NULL;
  537.     curr_image.red = NULL;
  538.     curr_image.green = NULL;
  539.     curr_image.blue = NULL;
  540.  
  541.     curr_image.expanded = var_table[i].expanded;
  542.     curr_image.zoomx = var_table[i].zoomx;
  543.     curr_image.zoomy = var_table[i].zoomy;
  544.  
  545.     curr_image.in_use = 0;
  546.  
  547.     reset_pos ();
  548.     return;
  549. }
  550. /* EOF */
  551. /* cat > src+obj/stack/stack_event.c << "EOF" */
  552. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  553. /* stack_event: event handler for store, show or delete */
  554. /*        stacking button                */
  555. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  556. /* SCCS information: %W%    %G% - NCSA */
  557.  
  558. /* #include "stack.h" */
  559.  
  560. stack_event (item, event)
  561.     Panel_item      item;
  562.     Event          *event;
  563. {
  564.     int             which_button, i;
  565.  
  566.     which_button = (int) panel_get (item, PANEL_CLIENT_DATA);
  567.  
  568.         /* will need the button type in the menu to tell what to do */
  569.     menu_set (stack_menu, MENU_CLIENT_DATA, which_button, 0);
  570.     menu_set (show_menu, MENU_CLIENT_DATA, which_button, 0);
  571.  
  572.         /* store  -> stack_menu
  573.            show   -> show_menu
  574.            delete -> stack_menu */
  575.  
  576.     if (display_panel_menu (item, event, panel, (which_button != 2) ? stack_menu : show_menu))
  577.         switch (which_button)
  578.         {
  579.             case 1:/* store */
  580.                     /* find next available empty slot */
  581.                 for (i = 0; i < MAXTABLE + 1; i++)
  582.                     if (var_table[i].in_use != 1)
  583.                         break;
  584.                 if (i < MAXTABLE + 1)
  585.                     store_image (i);
  586.                 else
  587.                     msg_write ("Error: Stack table full! Please delete or flush and try again.");
  588.                 break;
  589.  
  590.             case 2:/* show */
  591.                     /* find first full slot */
  592.                 for (i = 0; i < MAXTABLE + 1; i++)
  593.                     if (var_table[i].in_use == 1)
  594.                         break;
  595.                 if (i < MAXTABLE + 1)
  596.                     show_entryimage (i);
  597.                 else
  598.                     msg_write ("Warning: Stack table empty! Nothing shown.");
  599.                 break;
  600.  
  601.             case 3:/* delete */
  602.                 msg_write ("Note: You must explicitly select an entry to delete.");
  603.                 break;
  604.         }
  605. }
  606. /* EOF */
  607. /* cat > src+obj/stack/stack_mark_menu.c << "EOF" */
  608. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  609. /* stack_mark_menu: menu generate proc to mark menu    */
  610. /*            before displaying for store, show    */
  611. /*            or delete stacking button menu.    */
  612. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  613. /* SCCS information: %W%    %G% - NCSA */
  614.  
  615. /* #include "stack.h" */
  616.  
  617. Menu 
  618. stack_mark_menu (m, operation)
  619.     Menu            m;
  620.     Menu_generate   operation;
  621. {
  622.     int             which_button, i;
  623.  
  624.     switch (operation)
  625.     {
  626.         case MENU_DISPLAY:
  627.             which_button = (int) menu_get (m, MENU_CLIENT_DATA);
  628.             switch (which_button)
  629.             {
  630.                 case 1:        /* store */
  631.                     for (i = 0; i < MAXTABLE + 1; i++)
  632.                         menu_set ((Menu_item) menu_get (m, MENU_NTH_ITEM, i + 1, 0), MENU_INACTIVE, (var_table[i].in_use != 1) ? FALSE : TRUE, 0);
  633.                     break;
  634.  
  635.                 case 2:        /* show */
  636.                     for (i = 0; i < MAXTABLE + 1; i++)
  637.                         menu_set ((Menu_item) menu_get (m, MENU_NTH_ITEM, i + 1, 0), MENU_INACTIVE, (var_table[i].in_use != 1) ? TRUE : FALSE, 0);
  638.                     break;
  639.  
  640.                 case 3:        /* delete */
  641.                     for (i = 0; i < MAXTABLE + 1; i++)
  642.                         menu_set ((Menu_item) menu_get (m, MENU_NTH_ITEM, i + 1, 0), MENU_INACTIVE, (var_table[i].in_use != 1) ? TRUE : FALSE, 0);
  643.                     break;
  644.             }
  645.  
  646.             break;
  647.  
  648.         case MENU_DISPLAY_DONE:
  649.  
  650.             break;
  651.  
  652.         case MENU_NOTIFY:
  653.  
  654.             break;
  655.  
  656.         case MENU_NOTIFY_DONE:
  657.  
  658.             break;
  659.     }
  660.         /* The current or newly-created menu is returned */
  661.     return m;
  662. }
  663. /* EOF */
  664. /* cat > src+obj/stack/stack_proc.c << "EOF" */
  665. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  666. /* stack_proc: stack routine                */
  667. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  668. /* SCCS information: %W%    %G% - NCSA */
  669.  
  670. /* #include "stack.h" */
  671.  
  672. stack_proc (m, mi)
  673.     Menu            m;
  674.     Menu_item       mi;
  675. {
  676.         /* remove animation buttons if there */
  677.     invalid_ani ();
  678.  
  679.         /* show buttons for stack operation */
  680.     valid_stack ();
  681. }
  682. /* EOF */
  683. /* cat > src+obj/stack/stack_request.c << "EOF" */
  684. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  685. /* stack_request: menu notify proc for store, show or    */
  686. /*          delete stacking button        */
  687. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  688. /* SCCS information: %W%    %G% - NCSA */
  689.  
  690. /* #include "stack.h" */
  691.  
  692. caddr_t 
  693. stack_request (m, mi)
  694.     Menu            m;
  695.     Menu_item       mi;
  696. {
  697.     int             which_button, index, i, which_entry, j;
  698.     char           *ptr;
  699.  
  700.     which_button = (int) menu_get (m, MENU_CLIENT_DATA);
  701. /* printf ("which_button = %d\n", which_button); */
  702.     switch (which_button)
  703.     {
  704.         case 1:    /* store */
  705.             index = (int) strtol (menu_get (mi, MENU_STRING), &ptr, 10);
  706.             store_image (index - 1);
  707.             break;
  708.  
  709.         case 2:    /* show image or entry data */
  710. /* printf ("menu string = %s\n", menu_get (mi, MENU_STRING)); */
  711.             if (strcmp (menu_get (mi, MENU_STRING), "Entry data"))
  712.             {        /* show image */
  713.                 if ((int) window_get (entry_frame, WIN_SHOW) == TRUE)
  714.                     window_set (entry_frame, WIN_SHOW, FALSE, 0);
  715.                 index = (int) strtol (menu_get (mi, MENU_STRING), &ptr, 10);
  716.                 show_entryimage (index - 1);
  717.             }
  718.             else
  719.             {        /* show entry data */
  720.                 if ((int) window_get (entry_frame, WIN_SHOW))
  721.                     break;
  722.                 if ((index = (int) strtol (panel_get (show_but_msg, PANEL_LABEL_STRING), &ptr, 10)) == 0)
  723.                 {        /* find first full slot */
  724.                     for (i = 0; i < MAXTABLE + 1; i++)
  725.                         if (var_table[i].in_use == 1)
  726.                             break;
  727.                     if (i < MAXTABLE + 1)
  728.                         display_entrysw (i);
  729.                     else
  730.                         msg_write ("Warning: Stack table empty! Nothing to show.");
  731.                 }
  732.                 else
  733.                     display_entrysw (index - 1);
  734.             }
  735.             break;
  736.  
  737.         case 3:    /* delete */
  738.             index = (int) strtol (menu_get (mi, MENU_STRING), &ptr, 10);
  739.             delete_entry (index - 1);
  740.                 /* if entry window is up and the entry being
  741.                    shown has just been deleted display the
  742.                    next higher entry or close the window if
  743.                    no entries left. */
  744.             if ((int) window_get (entry_frame, WIN_SHOW))
  745.             {
  746.                 if ((which_entry = (int) window_get (entry_frame, WIN_CLIENT_DATA)) == index)
  747.                 {
  748.                     which_entry--;
  749.                     j = (which_entry == MAXTABLE) ? 0 : which_entry + 1;
  750.                     for (i = 0; i < MAXTABLE + 1; i++)
  751.                         if (var_table[j].in_use == 1)
  752.                             break;
  753.                         else
  754.                             j = (j == MAXTABLE) ? 0 : j + 1;
  755.                     if (i < MAXTABLE + 1)
  756.                         set_entry (j);
  757.                     else
  758.                     {
  759.                         window_set (entry_frame, WIN_SHOW, FALSE, 0);
  760.                         msg_write ("Warning: Stack table empty! Nothing to show.");
  761.                     }
  762.                 }
  763.             }
  764.             break;
  765.     }
  766. }
  767. /* EOF */
  768. /* cat > src+obj/stack/store_image.c << "EOF" */
  769. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  770. /* store_image: store image into a memory slot        */
  771. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  772. /* SCCS information: %W%    %G% - NCSA */
  773.  
  774. /* #include "stack.h" */
  775.  
  776. store_image (value)
  777.     int             value;
  778. {
  779.     square_drawn = line_drawn = 0;
  780.     first_middle_down = 0;
  781.     clear_request = 0;
  782.  
  783.     put_table (value);
  784.     return;
  785. }
  786. /* EOF */
  787. /* cat > src+obj/stack/store_in_mem.c << "EOF" */
  788. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  789. /* store_in_mem: store in memory            */
  790. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  791. /* SCCS information: %W%    %G% - NCSA */
  792.  
  793. /* #include "stack.h" */
  794.  
  795. store_in_mem (i)
  796.                  /* returns: error - 0 = no error
  797.                              1 = memory allocation */
  798.     int             i;
  799.                 /* input: entry index in table */
  800. {
  801.     int             lastw = curr_image.xdim;
  802.     int             lasth = curr_image.ydim;
  803.  
  804.         /* allocation and fill RGB */
  805.     if ((var_table[i].red = (unsigned char *) malloc (LUTSIZE)) == NULL)
  806.         return (1);
  807.     if ((var_table[i].green = (unsigned char *) malloc (LUTSIZE)) == NULL)
  808.     {
  809.         free (var_table[i].red);
  810.         return (1);
  811.     }
  812.     if ((var_table[i].blue = (unsigned char *) malloc (LUTSIZE)) == NULL)
  813.     {
  814.         free (var_table[i].red);
  815.         free (var_table[i].green);
  816.         return (1);
  817.     }
  818.     pw_getcolormap (pw, 0, color_index, var_table[i].red, var_table[i].green, var_table[i].blue);
  819.     
  820.     if ((var_table[i].image = mem_create (lastw, lasth, PIXDEPTH)) == NULL)
  821.         return (1);
  822.  
  823.     pw_read (var_table[i].image, 0, 0, lastw, lasth, PIX_SRC, pw, startx, starty);
  824.     return (0);
  825. }
  826. /* EOF */
  827. /* cat > src+obj/stack/valid_stack.c << "EOF" */
  828. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  829. /* valid_stack: valid stack                */
  830. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  831. /* SCCS information: %W%    %G% - NCSA */
  832.  
  833. /* #include "stack.h" */
  834.  
  835. valid_stack ()
  836. {
  837.     Menu_item       item;
  838.  
  839.         /* store button and entry number */
  840.     panel_set (store_but, PANEL_SHOW_ITEM, TRUE, 0);
  841.     panel_set (store_but_msg, PANEL_SHOW_ITEM, TRUE, 0);
  842.  
  843.         /* show button and entry number */
  844.     panel_set (show_but, PANEL_SHOW_ITEM, TRUE, 0);
  845.     panel_set (show_but_msg, PANEL_SHOW_ITEM, TRUE, 0);
  846.  
  847.         /* delete button and entry number */
  848.     panel_set (delete_but, PANEL_SHOW_ITEM, TRUE, 0);
  849.     panel_set (delete_but_msg, PANEL_SHOW_ITEM, TRUE, 0);
  850.  
  851.         /* clear table button */
  852.     panel_set (flush_but, PANEL_SHOW_ITEM, TRUE, 0);
  853.  
  854.         /* disable animation */
  855.     item = menu_get (image_menu, MENU_NTH_ITEM, 3, 0);
  856.     menu_set (item, MENU_INACTIVE, TRUE, 0);
  857. }
  858. /* EOF */
  859.